<?php
/**
 * Created by PhpStorm.
 * User: XYX
 * Date: 2017/8/29
 * Time: 16:40
 */

namespace App\Api\Transformers;
use App\Twitter;
use League\Fractal\TransformerAbstract;
class TwitterTransformer extends TransformerAbstract
{
    protected $defaultIncludes = ['consumer', 'twitterpics'];
    public function transform(Twitter $item)
    {
        return
            [
                'id'=>$item['id'],
                'body'=>'#'.$item['clubname'].'#'.$item['content'],
                'username'=>$item->consumer->nickname,
                'likes'=>$item['likes']
            ];
    }
    public function includeConsumer(Twitter $twitter){
        if (! ($twitter->consumer)) {
            return $this->null();
        }
        return $this->item($twitter->consumer, new TwitterConsumerTransformer());
    }
    public function includeTwitterpics(Twitter $twitter)
    {
        if (! ($twitter->twitterpics)) {
            return $this->null();
        }
        return $this->collection($twitter->twitterPics,new PicforTwitterTransformer());
    }
}